﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using StripeOne.ShortenUrl.API.Common;
using StripeOne.ShortenUrl.Datalayer;
using StripeOne.ShortenUrl.Model.Request;
using StripeOne.ShortenUrl.Database;
using StripeOne.ShortenUrl.Model;

namespace StripeOne.ShortenUrl.API.Controllers
{
    public class ShortenController : ShortenApiController
    {
        [HttpPost]
        public ShortenApiResult<ShortenModel> ShortIt([FromBody]ShortenRequest request)
        {
            var obj = new ShortenModel()
            {
                UserId = request.UserId,
                OriginalUrl = request.Url
            };
            return Run(() => ShortenUrlDatalayer.Shorten.ShortIt(obj));
        }

        public ShortenApiResult<ShortenModel> Get(int id)
        {
            return Run(() => ShortenUrlDatalayer.Shorten.Get(id));
        }

        public ShortenApiResult<ShortenModel[]> GetAll(int userId)
        {
            return RunWithPaging(() => ShortenUrlDatalayer.Shorten.GetAll(userId));
        }
    }
}